package liuliu.throughwaring.ui.fragment;

import android.app.AlertDialog;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.tsz.afinal.annotation.view.CodeNote;

import liuliu.custom.control.toast.CustomeDialog;
import liuliu.custom.method.Utils;
import liuliu.throughwaring.R;
import liuliu.throughwaring.base.BaseFragment;
import liuliu.throughwaring.service.UpdateMain;
import liuliu.throughwaring.ui.activity.ActivitySearchCompanyList;
import liuliu.throughwaring.ui.activity.CongyeActivity;
import liuliu.throughwaring.ui.activity.MainsActivity;
import liuliu.throughwaring.ui.activity.NewCompanyList;
import liuliu.throughwaring.ui.activity.OnLineSearchActivity;
import liuliu.throughwaring.ui.activity.SearchNoticeList;
import liuliu.throughwaring.ui.activity.PoliceAndLiuDongActivity;
import liuliu.throughwaring.ui.activity.WaringActivity;

/**
 * 作者：柳伟杰 on 2016/3/14 15:15
 * 邮箱：1031066280@qq.com
 */
public class ShouYeFragment extends BaseFragment {
    @CodeNote(id = R.id.congye_shouye_ll, click = "onClick")
    LinearLayout congye_shouye_ll;
    @CodeNote(id = R.id.liudong_shouye_ll, click = "onClick")
    LinearLayout liudong_shouye_ll;
    @CodeNote(id = R.id.zulin_shouye_ll, click = "onClick")
    LinearLayout zulin_shouye_ll;
    @CodeNote(id = R.id.minjing_shouye_ll, click = "onClick")
    LinearLayout minjing_shouye_ll;
    @CodeNote(id = R.id.waring_shouye_ll, click = "onClick")
    LinearLayout waring_shouye_ll;
    @CodeNote(id = R.id.lianwang_shouye_ll, click = "onClick")
    LinearLayout lianwang_shouye_ll;
    @CodeNote(id = R.id.main_company_list, click = "onClick")
    LinearLayout companyList;
    @CodeNote(id = R.id.main_notice, click = "onClick")
    LinearLayout mainNotice;
    @CodeNote(id = R.id.shouye_notice_num)
    TextView noticeNum;
    @CodeNote(id = R.id.shouye_company_num, click = "onClick")
    TextView companyNum;
    UpdateMain.UpdateMainBind binder = null;
    Utils mUtils;

    @Override
    public void initViews() {
        setContentView(R.layout.frag_shouye);
        mUtils = new Utils(MainsActivity.mIntails);
        Intent intent = new Intent(MainsActivity.mIntails, UpdateMain.class);
        MainsActivity.mIntails.bindService(intent, conn, Context.BIND_AUTO_CREATE);
    }

    @Override
    public void initEvents() {

    }

    private ServiceConnection conn = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder iBinder) {
            binder = (UpdateMain.UpdateMainBind) iBinder;
            if (binder != null) {
                binder.Refush(new UpdateMain.GetNoticeFace() {
                    @Override
                    public void FaceShow(int companyCount, int noticeCount) {
                        companyNum.setText(companyCount + "条");
                        noticeNum.setText(noticeCount + "条");
                    }
                });
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
        }
    };

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.congye_shouye_ll://从业人员
                mUtils.IntentPost(CongyeActivity.class, new Utils.putListener() {
                    @Override
                    public void put(Intent intent) {
                        intent.putExtra("style", "congye");
                    }
                });
                break;
            case R.id.liudong_shouye_ll://流动人员
                mUtils.IntentPost(PoliceAndLiuDongActivity.class, new Utils.putListener() {
                    @Override
                    public void put(Intent intent) {
                        intent.putExtra("style", "liudong");
                    }
                });
                break;
            case R.id.zulin_shouye_ll://租赁人员
                mUtils.IntentPost(CongyeActivity.class, new Utils.putListener() {
                    @Override
                    public void put(Intent intent) {
                        intent.putExtra("style", "zulin");
                    }
                });
                break;
            case R.id.minjing_shouye_ll://民警管理
                mUtils.IntentPost(PoliceAndLiuDongActivity.class, new Utils.putListener() {
                    @Override
                    public void put(Intent intent) {
                        intent.putExtra("style", "police");
                    }
                });
                break;
            case R.id.waring_shouye_ll://报警比对
                mUtils.IntentPost(WaringActivity.class);
                break;
            case R.id.main_company_list:
                mUtils.IntentPost(NewCompanyList.class);
                break;
            case R.id.main_notice:
                mUtils.IntentPost(SearchNoticeList.class);
                break;
            case R.id.lianwang_shouye_ll://联网查询
                mUtils.IntentPost(OnLineSearchActivity.class);
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MainsActivity.mIntails.unbindService(conn);
    }
}
